﻿@page "/xlsio/worksheet-to-html"
@inject Microsoft.JSInterop.IJSRuntime JS
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@using System.IO;

@using Syncfusion.Blazor.Buttons
@*Hidden:Lines*@

@using BlazorDemos.Data.FileFormats.XlsIO

@*End:Hidden*@
@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates how to convert Worksheets to html files using Essential XlsIO.</p>
</SampleDescription>
<ActionDescription>
  <p>This sample demonstrates how a worksheet or workbook is converted to HTML. The output file can be saved to disc and also as a memory stream.</p> 
</ActionDescription>

<div class="control-section">
    <p style="font-weight:normal">Click the button below to view the converted HTML document using Essential XlsIO.</p>

    <div class="radio-control">
        <h5 class="row">Convert Type:</h5>
        <div class="e-radio-wrapper">
            <SfRadioButton Label="Workbook" Name="Workbook" Value=@("Workbook") @bind-Checked="@convertType"></SfRadioButton>
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <div class="e-radio-wrapper">
            <SfRadioButton Label="Worksheet" Name="Worksheet" Value=@("Worksheet") @bind-Checked="@convertType"></SfRadioButton>
        </div>
    </div>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="InputTemplate">Input Template</SfButton>&nbsp;
                    <SfButton @onclick="Convert">Convert</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .radio-control {
        margin: 5% 0 2% 0;
    }

    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream excelStream;
    string convertType = "Workbook";
    string button = string.Empty;

    /// <summary>
    /// Convert the Excel document to HTML
    /// </summary>
    public async Task Convert()
    {
        WorksheetToHTMLService service = new WorksheetToHTMLService(hostingEnvironment);
        button = "Convert";
        excelStream = service.WorksheetToHTMLXlsIO(button, convertType);
        await JS.SaveAs("Sample.html", excelStream.ToArray());
    }
    /// <summary>
    /// Download the Excel document used for conversion
    /// </summary>
    public async Task InputTemplate()
    {
        WorksheetToHTMLService service = new WorksheetToHTMLService(hostingEnvironment);
        button = "Input Template";
        excelStream = service.WorksheetToHTMLXlsIO(button, convertType);
        await JS.SaveAs("Template.xlsx", excelStream.ToArray());
    }
}
